#include<iostream>
#include<pthread.h>
using std::cout;
using std::endl;

class Com
{
public:
    static Com* getinstance()
    {
            pthread_once(&_once,_func);
            return _p;
    }

private:
    static void _func()
    {
        _p=new Com();
        atexit(destroy);
    }
    static void destroy()
    {
        if(_p)
        {
            delete _p;
            _p=nullptr;
        }
    }
    ~Com()
    {
        cout<<"xigou"<<endl;
    }
    int _x=1;
    static Com *_p;
    static pthread_once_t _once;
};

Com* Com::_p=nullptr;
pthread_once_t Com::_once=PTHREAD_ONCE_INIT;
int main()
{
    Com::getinstance();
}

